use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("欢迎来玩猜数字游戏!");

    let secret_number = rand::thread_rng().gen_range(1, 101);

    //    println!("秘密数字就是：{}", secret_number);

    loop {
        println!("请输入您要猜的数字");

        let mut guess = String::new();

        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        }
        //            .expect("请输入一个数字！")
        ;

        println!("您猜的数字是: {}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("太小了!"),
            Ordering::Greater => println!("太大了!"),
            Ordering::Equal => {
                println!("猜对了!");
                break;
            }
        }
    }
}
